import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.ITypeConvert;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;

/**
 * @描述：MYSQL自定义字段类型转化器
 * @作者：lixing_java@163.com
 * @时间：2020/4/13 13:25
 */
public class CustomMysqlTypeConvert extends MySqlTypeConvert implements ITypeConvert {
    @Override
    public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
        String t = fieldType.toLowerCase();
        if (t.contains("tinyint")) {
            return DbColumnType.INTEGER;
        }
        if (t.contains("bigint")) {
            return DbColumnType.LONG;
        }
        if (t.contains("int")) {
            return DbColumnType.INTEGER;
        }
        if (t.contains("datetime")) {
            return DbColumnType.DATE;
        }
        if (t.contains("timestamp")) {
            return DbColumnType.DATE;
        }
        return super.processTypeConvert(globalConfig, fieldType);
    }
}
